<include file="../header" />
<div class="wrapper">
    <div class="header text-center font-16">
        公共报修
        <div class="iconfont icon-zuo go_index"></div>
    </div>
    <div class="history-list">
        <div class="addimg clearfix">
            <div class="load-img pull-left" id="repair_image">
                <div class="img">
                    <div class="load text-center">
                        +
                    </div>
                </div>
            </div>
        </div>
        <div class="repair-list describe-content">
            <input type="text" placeholder="请描述报修内容" id="content">
        </div>
        <input type="hidden" id="public_id" value="{BEESCRM:$data.public_id}">
        <input type="hidden" id="community_id" value="{BEESCRM:$community.community_id}">
        <input type="hidden" id="building_id" value="{BEESCRM:$building.building_id}">
        <input type="hidden" id="floor_id" value="{BEESCRM:$floor.floor_id}">
        <div class="repair-list gray2 form-control">
            报修项目
            <select  class="select" id="public_name" >
                <option value="0">请选择报修项目</option>
                <volist name="project" id="vo">
                    <option value="{BEESCRM:$vo.project_name}">{BEESCRM:$vo.project_name}</option>
                </volist>
            </select>
        </div>
        <div class="repair-list gray2">
            报修地址
            <p style="color:#000;">
                <span id="community_name">{BEESCRM:$community.community_name}</span>
                <span id="building_name">{BEESCRM:$building.building_name}</span>
                <span id="floor_name">{BEESCRM:$floor.floor_name}</span>
            </p>
        </div>
        <input type="hidden" id="serverId" value=""/>
    </div>
    <div class="flex repair-btn">
        <a href="#" class="btn text-center btn-left" id="order_submit">提交</a>
        <a href="javascript:history.back();" class="btn text-center btn-right gray-bg">取消</a>
    </div>
</div>
<include file="../getphotos"/>
<script src="/assets/repaireast/js/layer.js"></script>
<script src="/assets/repaireast/js/public.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.iframe-transport.js"></script>
<script>
    /*$('.img').click(function () {
        $('.file').click();
    })

    //图片上传
    $(".file").fileupload({
        url:"/Base/Common/upload/is_thumb/1",//文件上传地址，当然也可以直接写在input的data-url属性内
//        beforeSend:function(){
//            $('.load').show();
//        },
        done:function(e,result){
            //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
            //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
            //返回的数据在result.result中，假设我们服务器返回了一个json对象
            var data=$.parseJSON(result.result);
            if(data.status=='S'){
                var html = '<img src="'+data.thumb_url+'">';
                $('#repair_image .img').html(html);
            }else{
                fm.alert(data.message);
                return false;
            }
        }
    });*/

    $(function(){
        var serverId = '';
        $('.img').click(function () {
            wx.ready(function () {
                wx.chooseImage({
                    count: 1, // 默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                    success: function (res) {
                        var localIds = res.localIds;
                        $('#repair_image .img').html('<img src="' + localIds[0] + '">');

                        var localId = localIds.pop();
                        wx.uploadImage({
                            localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
                            isShowProgressTips: 1, // 默认为1，显示进度提示
                            success: function (res) {
                                serverId = res.serverId; // 返回图片的服务器端ID
                                $('#serverId').val(serverId);
                            }
                        });
                    }
                });
            });
        })
    })

    //提交数据
    $('#order_submit').click(function(){
        var can_submit = 1;
        var image = $('#repair_image img').attr('src');
        if (!image){
            fm.alert('请上传报修图片！');
            return false;
            can_submit = 0;
        }
        var content = $('#content').val();
        if (!content){
            fm.alert('请描述报修内容！');
            return false;
            can_submit = 0;
        }

        var public_name = $('#public_name').val();
        if (!public_name){
            fm.alert('请选择报修项目！');
            return false;
            can_submit = 0;
        }
        var public_id = $('#public_id').val();
        var public_name = $('#public_name').val();
        var community_id = $('#community_id').val();
        var community_name = $('#community_name').text();
        var building_id = $('#building_id').val();
        var building_name = $('#building_name').text();
        var floor_id = $('#floor_id').val();
        var floor_name = $('#floor_name').text();
        var serverId = $('#serverId').val();
        if (can_submit == 1) {
            $.ajax({
                type: 'POST',
                url: "/Repaireast/RepaireastRepair/doPublicRepair",
                dataType: 'json',
                data: {
                    'image' : image,
                    'content': content,
                    'public_id': public_id,
                    'public_name': public_name,
                    'community_id': community_id,
                    'community_name':community_name,
                    'building_id':building_id,
                    'building_name':building_name,
                    'floor_id':floor_id,
                    'floor_name':floor_name,
                    'serverId':serverId
                },
                //data: "content="+content+"&content="+content+"&public_id="+public_id+"&public_name="+public_name+"&community_id="+community_id+"&community_name="+community_name+"&building_id="+building_id+"&building_name="+building_name+"&floor_id="+floor_id+"&floor_name="+floor_name+"&serverId="+serverId,
                success: function (data) {
                	if(data.status == "S"){               		
                		fm.alert(data.message);
                		setTimeout(function () {
                		    window.location.href = data.url;
                		}, 2000);
                	}else{
                		fm.alert(data.message);   
                	}
                },
                error: function () {
                    fm.alert('通讯失败，请稍后再试');                   
                }
            });
        }
    });
</script>
<include file="../footer" />